<template>
  <div>
    <component :is="loadedComponent" v-bind="initialData" />
  </div>
</template>

<script>
import { all } from "@/api/lc/biz";
const componentMap = {
  LEAVE_INFO: () => import("@/views/oa/leave/leaveForm.vue"),
};

export default {
  props: {
    componentName: {
      type: String,
      required: true,
    },
    initialData: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      loadedComponent: null,
    };
  },
  async created() {
    const { data } = await all();
    console.log(data)
    const componentLoader = componentMap[this.componentName];
    if (componentLoader) {
      try {
        const component = await componentLoader();
        this.loadedComponent = component.default;
      } catch (error) {
        console.error("Error loading component:", error);
      }
    } else {
      console.error("Component not found in map:", this.componentName);
    }
  },
};
</script>
